{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n=int(input())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sets=(1,2,3,4,5,6,7,8,9)\n",
    "def getNum(i,j):\n",
    "    sum=0\n",
    "    for i in range(i,j):\n",
    "        sum=sum*1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def find(n):\n",
    "    res=[]\n",
    "    for i in range(1,n+1):\n",
    "        if '2'in str(i):\n",
    "            res.append(str(i).count('2'))\n",
    "            #print(res)\n",
    "    #print(res)\n",
    "    return res\n",
    "sum(find(2020))      \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#寻找2020\n",
    "content = []\n",
    "count=0\n",
    "with open('D:\\\\蓝桥杯训练\\\\2020.txt') as fp:\n",
    "    for line in fp.readlines():\n",
    "        count+=1\n",
    "        content.append((line.strip()))\n",
    "res = 0\n",
    "#遍历每一行\n",
    "for i in range(300):\n",
    "    for j in range(297):\n",
    "        if content[i][j] == '2' and content[i][j+1] == '0' and content[i][j+2] == '2' and content[i][j+3] == '0':\n",
    "            res += 1\n",
    "#遍历每一列\n",
    "for a in range(297):\n",
    "    for b in range(300):\n",
    "        if content[a][b] == '2' and content[a+1][b] == '0' and content[a+2][b] == '2' and content[a+3][b] == '0':\n",
    "            res += 1\n",
    "\n",
    "#左上到右下的情况\n",
    "for c in range(297):\n",
    "    for d in range(297):\n",
    "        if content[c][d] == '2' and content[c+1][d+1] == '0' and content[c+2][d+2] == '2' and content[c+3][d+3] == '0':\n",
    "            res += 1\n",
    "\n",
    "print(res)\n",
    "print(count)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#跑步锻炼\n",
    "import calendar\n",
    "\n",
    "cal = calendar.month(2000, 1)\n",
    "print (\"以下输出2000年1月份的日历:\")\n",
    "print (cal)\n",
    "common_year=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "leap_year=[31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "months=list(range(1,13))\n",
    "ten_months=list(range(1,11))\n",
    "ten_leap_year=[31,29,31,30,31,30,31,31,30,1]\n",
    "kilometre=0\n",
    "w=5\n",
    "for year in range(2000,2021):\n",
    "    if year==2020:\n",
    "            for month in ten_months:\n",
    "                for day in range(1,ten_leap_year[month-1]+1):\n",
    "                    week=w%7+1  #5是因为2000年1.1是周六\n",
    "                    \n",
    "                    if week==1 or day==1:\n",
    "                        kilometre+=2\n",
    "                    else:\n",
    "                        kilometre+=1\n",
    "                    #print(\"小蓝{}年{}月{}日跑了{}千米\".format(year,month,day,kilometre))\n",
    "                    w+=1\n",
    "    else:\n",
    "        if year%4==0:\n",
    "            for month in months:\n",
    "                for day in range(1,leap_year[month-1]+1):\n",
    "                    week=w%7+1  #5是因为2000年1.1是周六                    \n",
    "                    if week==1 or day==1:\n",
    "                        kilometre+=2\n",
    "                    else:\n",
    "                        kilometre+=1\n",
    "                    #print(\"小蓝{}年{}月{}日跑了{}千米\".format(year,month,day,kilometre))\n",
    "                    w+=1\n",
    "        else:\n",
    "             for month in months:\n",
    "                for day in range(1,common_year[month-1]+1):\n",
    "                    week=w%7+1  #5是因为2000年1.1是周六\n",
    "                    \n",
    "                    if week==1 or day==1:\n",
    "                        kilometre+=2\n",
    "                    else:\n",
    "                        kilometre+=1\n",
    "                    #print(\"小蓝{}年{}月{}日跑了{}千米\".format(year,month,day,kilometre))\n",
    "                    w+=1\n",
    "print(\"小蓝跑的公里数：\",kilometre)               "
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    " 数字 n 代表生成括号的对数，请你设计一个函数，用于能够生成所有可能的并且 有效的 括号组合。\n",
    "\n",
    "【示例】\n",
    "\n",
    "输入：n = 3\n",
    "输出：[\n",
    "“((()))”,\n",
    "“(()())”,\n",
    "“(())()”,\n",
    "“()(())”,\n",
    "“()()()”\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "[\n",
      "\n",
      "\"(((())))\"\n",
      "\n",
      "\"((()()))\"\n",
      "\n",
      "\"((())())\"\n",
      "\n",
      "\"((()))()\"\n",
      "\n",
      "\"(()(()))\"\n",
      "\n",
      "\"(()()())\"\n",
      "\n",
      "\"(()())()\"\n",
      "\n",
      "\"(())(())\"\n",
      "\n",
      "\"(())()()\"\n",
      "\n",
      "\"()((()))\"\n",
      "\n",
      "\"()(()())\"\n",
      "\n",
      "\"()(())()\"\n",
      "\n",
      "\"()()(())\"\n",
      "\n",
      "\"()()()()\"\n",
      "\n",
      "]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "result_lis=[]  #存放结果的列表\n",
    "def dfs_bracket_match(left_nm,right_nm,s):  \n",
    "    '使用dfs方式进行括号匹配'\n",
    "    if(left_nm<0 and right_nm<0):\n",
    "        return  #所有节点使用完毕，结束\n",
    "    if(left_nm==0 and right_nm==0):\n",
    "        result_lis.append(s)\n",
    "    if(left_nm>0):\n",
    "        dfs_bracket_match(left_nm-1,right_nm,s+'(')\n",
    "    if(left_nm<right_nm):\n",
    "        dfs_bracket_match(left_nm,right_nm-1,s+')')\n",
    "    return result_lis\n",
    "n=int(input())\n",
    "print('[\\n')\n",
    "for result in dfs_bracket_match(n,n,''):\n",
    "    print('\"'+result+'\"'+'\\n')\n",
    "print(']\\n')\n",
    "\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "给定三个整数 a, b, c，如果一个整数既不是 a 的整数倍也不是 b 的整数倍还不是 c 的整数倍，则这个数称为反倍数。\n",
    "请问在 1 至 n 中有多少个反倍数。\n",
    "【输入格式】\n",
    "输入的第一行包含一个整数 n。\n",
    "第二行包含三个整数 a, b, c，相邻两个数之间用一个空格分隔。\n",
    "【输出格式】\n",
    "输出一行包含一个整数，表示答案。\n",
    "【样例输入】\n",
    "30\n",
    "2 3 6\n",
    "【样例输出】\n",
    "10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n=int(input())\n",
    "a,b,c=map(int,(input().split()))\n",
    "def multiple(a,b,c,n):\n",
    "    count=0\n",
    "    for i in range(1,n+1):\n",
    "        if i%a!=0 and i%b!=0 and i%c!=0:\n",
    "            count+=1\n",
    "    return count\n",
    "print(multiple(a,b,c,n)) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如下图所示，小明用从1开始的正整数“蛇形”填充无限大的矩阵。\n",
    "\t\t\t\t1\t2\t6\t7\t15\t16  28\n",
    "\t\t\t\t3\t5\t8\t14\t17  27\n",
    "\t\t\t\t4\t9\t13\t18  26\n",
    "\t\t\t\t10\t12\t19  25\n",
    "\t\t\t\t11  20  24\n",
    "           21  23\n",
    "           22\n",
    "容易看出矩阵第二行第二列中的数是5。请计算出矩阵第20行第20列的数是多少？\n",
    "1 5 13 25  41\n",
    " 4 8 12  16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from functools import reduce\n",
    "def add(x,y):\n",
    "    return x+y\n",
    "print(reduce(add,[4*i for i in range(1,20)])+1)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "小蓝最近学习了一些排序算法，其中冒泡排序让他印象深刻。\n",
    "在冒泡排序中，每次只能交换相邻的两个元素。\n",
    "小蓝发现，如果对一个字符串中的字符排序，只允许交换相邻的两个字符，\n",
    "则在所有可能的排序方案中，冒泡排序的总交换次数是最少的。\n",
    "例如，对于字符串 lan 排序，只需要 1 次交换。对于字符串 qiao 排序，\n",
    "总共需要 4 次交换。\n",
    "小蓝找到了很多字符串试图排序，他恰巧碰到一个字符串，需要 100 次交\n",
    "换，可是他忘了吧这个字符串记下来，现在找不到了。\n",
    "请帮助小蓝找一个只包含小写英文字母且没有字母重复出现的字符串，对\n",
    "该串的字符排序，正好需要 100 次交换。如果可能找到多个，请告诉小蓝最短\n",
    "的那个。如果最短的仍然有多个，请告诉小蓝字典序最小的那个。请注意字符\n",
    "串中可以包含相同的字符。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bubble_sort(lis):\n",
    "    count=0\n",
    "    for i in range(len(lis)):\n",
    "        for j in range(len(lis)-i-1):\n",
    "            if lis[j]>lis[j+1]:\n",
    "                lis[j],lis[j+1]=lis[j+1],lis[j]\n",
    "                count+=1\n",
    "    return lis,count\n",
    "bubble_sort(list(\"jonmlkihgfedcba\"))\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "成绩统计：\n",
    "小蓝给学生们组织了一场考试，卷面总分为 100 分，每个学生的得分都是一个 0 到 100 的整数。\n",
    "如果得分至少是 60 分，则称为及格。如果得分至少为 85 分，则称为优秀。\n",
    "请计算及格率和优秀率，用百分数表示，百分号前的部分四舍五入保留整数。\n",
    "【输入格式】\n",
    "输入的第一行包含一个整数 n，表示考试人数。\n",
    "接下来 n 行，每行包含一个 0 至 100 的整数，表示一个学生的得分。\n",
    "【输出格式】\n",
    "输出两行，每行一个百分数，分别表示及格率和优秀率。\n",
    "百分号前的部分四舍五入保留整数。\n",
    "【样例输入】\n",
    "7\n",
    "80\n",
    "92\n",
    "56\n",
    "74\n",
    "88\n",
    "100\n",
    "0\n",
    "【样例输出】\n",
    "71%\n",
    "43%\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "student_count=int(input())\n",
    "lis_cores=[]\n",
    "pass_count=0\n",
    "great_count=0\n",
    "for i in range(student_count):\n",
    "    a=int(input())\n",
    "    if a>=60:\n",
    "        pass_count+=1\n",
    "    if a>=85:\n",
    "        great_count+=1\n",
    "   #lis_cores.append(a)\n",
    "#print(lis_cores)\n",
    "# for i in lis_cores:\n",
    "#     if i>=60:\n",
    "#         pass_count+=1\n",
    "#     if i>=85:\n",
    "#         great_count+=1\n",
    "print('{:.0%}'.format(pass_count/student_count))\n",
    "print('{:.0%}'.format(great_count/student_count))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "单词分析：\n",
    "【问题描述】\n",
    "小蓝正在学习一门神奇的语言，这门语言中的单词都是由小写英文字母组成，有些单词很长，远远超过正常英文单词的长度。\n",
    "小蓝学了很长时间也记不住一些单词，他准备不再完全记忆这些单词，而是根据单词中哪个字母出现得最多来分辨单词。\n",
    "现在，请你帮助小蓝，给了一个单词后，帮助他找到出现最多的字母和这个字母出现的次数。\n",
    "【输入格式】\n",
    "输入一行包含一个单词，单词只由小写英文字母组成。\n",
    "【输出格式】\n",
    "输出两行，第一行包含一个英文字母，表示单词中出现得最多的字母是哪个。\n",
    "如果有多个字母出现的次数相等，输出字典序最小的那个。\n",
    "第二行包含一个整数，表示出现得最多的那个字母在单词中出现的次数。\n",
    "【样例输入】\n",
    "lanqiao\n",
    "【样例输出】\n",
    "a\n",
    "2\n",
    "【样例输入】\n",
    "longlonglongistoolong\n",
    "【样例输出】\n",
    "o\n",
    "6\n",
    "【评测用例规模与约定】\n",
    "对于所有的评测用例，输入的单词长度不超过 1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "words=input()\n",
    "res=[]\n",
    "for i in words:\n",
    "    res.append(words.count(i))\n",
    "print(words[res.index(max(res))])\n",
    "print(max(res))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从三角形的顶部到底部有很多条不同的路径。\n",
    "对于每条路径，把路径上面的数加起来可以得到一个和，你的任务就是找到最\n",
    "大的和。路径上的每一步只能从一个数走到下一层和它最近的左边的那个数或者右边的那个数。此外，向左下走的次数与向右下走的次数相差不能超过 1。\n",
    "【输入格式】\n",
    "输入的第一行包含一个整数 N (1 < N ≤ 100)，表示三角形的行数。下面的\n",
    "N 行给出数字三角形。数字三角形上的数都是 0 至 100 之间的整数。\n",
    "【输出格式】\n",
    "输出一个整数，表示答案。\n",
    "【样例输入】\n",
    "5\n",
    "7\n",
    "3 8\n",
    "8 1 0\n",
    "2 7 4 4\n",
    "4 5 2 6 5\n",
    "【样例输出】\n",
    "27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import copy\n",
    "n=int(input())\n",
    "input_list=[]\n",
    "for i in range(n):\n",
    "    input_list.append(list(map(int,input().split())))\n",
    "temp_list=copy.deepcopy(input_list)\n",
    "for i in range(1,n):\n",
    "    for j in range(i):\n",
    "        temp_list[i][j]=max(temp_list[i-1][j],temp_list[i-1][j-1])+input_list[i][j]\n",
    "#print(temp_list)\n",
    "print(temp_list[n-1][int(n/2)] if n%2==1 else max(temp_list[n-1][n/2-1],temp_list[n-1][n/2]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "试题 I: 平面切分\n",
    "时间限制: 1.0s 内存限制: 512.0MB 本题总分：25 分\n",
    "【问题描述】\n",
    "平面上有 N 条直线，其中第 i 条直线是 y = Ai · x + Bi。\n",
    "请计算这些直线将平面分成了几个部分。\n",
    "【输入格式】\n",
    "第一行包含一个整数 N。\n",
    "以下 N 行，每行包含两个整数 Ai, Bi。\n",
    "【输出格式】\n",
    "一个整数代表答案。\n",
    "【样例输入】\n",
    "3\n",
    "1 1\n",
    "2 2\n",
    "3 3\n",
    "【样例输出】\n",
    "6\n",
    "【评测用例规模与约定】\n",
    "对于 50% 的评测用例，1 ≤ N ≤ 4, 10 ≤ Ai, Bi ≤ 10。\n",
    "对于所有评测用例，1 ≤ N ≤ 1000, 100000 ≤ Ai, Bi ≤ 100000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "1 1\n",
      "2 2\n",
      "3 3\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "N=int(input())\n",
    "input_lis=[]\n",
    "crosspoint_x_set=set()\n",
    "\n",
    "for i in range(N):\n",
    "    input_lis.append(list(map(int,input().split())))\n",
    "input_lis=list(set([tuple(t) for t in input_lis]))\n",
    "each_line_num_lis = [1] * (len(input_lis) + 1)\n",
    "for i in range(1,len(input_lis)):\n",
    "    crosspoint_x_set.clear()#crosspoint_x_set计算的第n条直线与前面直线的交点x，我们只需要的是set的长度，算出长度之后作为N加，然后clear，继续计算下一个条直线与前面直线的交点x\n",
    "    for n in range(i):\n",
    "        if input_lis[i-n-1][0]!=input_lis[i][0]:\n",
    "            x=round((input_lis[i][1]-input_lis[i-n-1][1])/(input_lis[i-n-1][0]-input_lis[i][0]),4)\n",
    "            crosspoint_x_set.add(x)\n",
    "    each_line_num_lis[i] += len(crosspoint_x_set)\n",
    "print(sum(each_line_num_lis) ) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：2.0s 内存限制：256.0MB\n",
    "　　为了吸引更多的顾客，某商场决定推行有奖抽彩活动。“本商场每日将产生一名幸运顾客，凡购买30元以上商品者均有机会获得本商场提供的一份精美礼品。”该商场的幸运顾客产生方式十分奇特：每位顾客可至抽奖台抽取一个幸运号码，该商场在抽奖活动推出的第i天将从所有顾客中（包括不在本日购物满30元者）挑出幸运号第i小的顾客作为当日的幸运顾客。该商场的商品本就价廉物美，自从有奖活动推出后，顾客更是络绎不绝，因此急需你编写一个程序，为他解决幸运顾客的产生问题。\n",
    "\n",
    "【输入数据】\n",
    "　　第1行一个整数N，表示命令数。\n",
    "　　第2~N+1行，每行一个数，表示命令。如果x>=0，表示有一顾客抽取了号码x；如果x=-1，表示傍晚抽取该日的幸运号码。\n",
    "【输出数据】\n",
    "　　对应各命令-1输出幸运号码；每行一个号码。(两个相同的幸运号看作两个号码)\n",
    "样例输入\n",
    "6\n",
    "3\n",
    "4\n",
    "-1\n",
    "-1\n",
    "3\n",
    "-1\n",
    "样例输出\n",
    "3\n",
    "4\n",
    "4\n",
    "\n",
    "解释\n",
    "\n",
    "　　只关注获奖的号码是多少，每个号码可以获奖多次。\n",
    "\n",
    "数据规模及约定\n",
    "\n",
    "　　共10组数据。\n",
    "　　对100%的数据，N=10^6所有命令为-1或int范围内的非负数，前i的命令中-1的数量不超过[i/2]（向下取整）。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "N=int(input())\n",
    "arr=[]\n",
    "result=[]\n",
    "for i in range(N):\n",
    "    item=int(input())\n",
    "    if item!=-1:\n",
    "        arr.append(item)\n",
    "    if item==-1:\n",
    "        arr.sort()\n",
    "        result.append(arr[i-len(arr)])\n",
    "for _ in result:\n",
    "    print(_)\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数学老师给小明出了一道等差数列求和的题目。但是粗心的小明忘记了一部分的数列，只记得其中 N 个整数。\n",
    "\n",
    "现在给出这 N 个整数，小明想知道包含这 N 个整数的最短的等差数列有几项？\n",
    "\n",
    "输入格式:\n",
    "输入的第一行包含一个整数 N。第二行包含 N 个整数 A1, A2, ..., AN。(注意 A1 ∼ AN 并不一定是按等差数列中的顺序给出)\n",
    "\n",
    "输出格式:\n",
    "输出一个整数表示答案。\n",
    "\n",
    "输入样例:\n",
    "5\n",
    "2 6 4 10 20\n",
    "输出样例:\n",
    "10\n",
    "数据范围：\n",
    "对于所有评测用例，2 ≤ N ≤ 100000，0 ≤ Ai ≤ 10^9。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "N=int(input())\n",
    "items=list(map(int,input().split()))\n",
    "items.sort()\n",
    "count=0\n",
    "min_diff=float('inf')\n",
    "for i in range(1,N):\n",
    "    diff=items[i]-items[i-1]\n",
    "    if diff<min_diff:\n",
    "        min_diff=diff\n",
    "for _ in range(items[0],items[N-1],min_diff):\n",
    "    count+=1\n",
    "print(count+1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    一个字符串的非空子串是指字符串中长度至少为 1 的连续的一段字符组成 的串。例如，字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab，一共 7 个。 注意在计算时，只算本质不同的串的个数。\n",
    "\n",
    "   请问，字符串0100110001010001 有多少个不同的非空子串？\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "chars=\"0100110001010001 \"\n",
    "b=set()\n",
    "length=len(chars)\n",
    "for j in range(length):\n",
    "    for i in range(length):\n",
    "        if i+j<length:\n",
    "            b.add(chars[i:i+j])\n",
    "#print(b)\n",
    "print(len(b)-1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "小明用字母A 对应数字1，B 对应2，以此类推，用Z 对应26。对于27\n",
    "以上的数字，小明用两位或更长位的字符串来对应，例如AA 对应27，AB 对\n",
    "应28，AZ 对应52，LQ 对应329。\n",
    "请问2019 对应的字符串是什么？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n",
    "n=2019\n",
    "chars=[]\n",
    "while n!=0:\n",
    "    remainder=n%26\n",
    "    n=n//26\n",
    "    chars.append(alpha[remainder-1])\n",
    "                \n",
    "for _ in chars:\n",
    "    print(_,end=\"\")\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "给定数列 1, 1, 1, 3, 5, 9, 17, …，从第 4 项开始，每项都是前 3 项的和。求第 20190324 项的最后 4 位数字。\n",
    "【答案提交】\n",
    "这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个 4 位整数（提示：答案的千位不为 0），在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "array=[1,1,1]\n",
    "j=0\n",
    "for i in range(3,20190324):\n",
    "    array.append(sum(array[j:i])%10000)\n",
    "    j+=1\n",
    "print(array[20190323])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "   把 2019 分解成 3 个各不相同的正整数之和，并且要求每个正整数都不包含数字 2 和 4，一共有多少种不同的分解方法？\n",
    "\n",
    "   注意交换 3 个整数的顺序被视为同一种方法，例如 1000+1001+18 和 1001+1000+18 被视为同一种。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40785\n"
     ]
    }
   ],
   "source": [
    "def check(x):\n",
    "    while x!=0:\n",
    "        t=x%10\n",
    "        x=int(x/10)\n",
    "        if t==2 or t==4:\n",
    "            return False\n",
    "    return True\n",
    "n=2019\n",
    "count=0\n",
    "for i in range(1,2019):\n",
    "    if check(i):\n",
    "        for j in range(i+1,2019):\n",
    "            if check(j):\n",
    "                k=2019-i-j\n",
    "                if k>j and check(k):\n",
    "                    count+=1\n",
    "print(count)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　给定n个十六进制正整数，输出它们对应的八进制数。\n",
    "\n",
    "输入格式\n",
    "　　输入的第一行为一个正整数n （1<=n<=10）。\n",
    "　　接下来n行，每行一个由0~9、大写字母A~F组成的字符串，表示要转换的十六进制正整数，每个十六进制数长度不超过100000。\n",
    "\n",
    "输出格式\n",
    "　　输出n行，每行为输入对应的八进制正整数。\n",
    "\n",
    "　　【注意】\n",
    "　　输入的十六进制数不会有前导0，比如012A。\n",
    "　　输出的八进制数也不能有前导0。\n",
    "\n",
    "样例输入\n",
    "　　2\n",
    "　　39\n",
    "　　123ABC\n",
    "\n",
    "样例输出\n",
    "　　71\n",
    "　　4435274\n",
    "\n",
    "　　【提示】\n",
    "　　先将十六进制数转换成某进制数，再由某进制数转换成八进制。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "39\n",
      "123ABC\n",
      "71\n",
      "4435274\n"
     ]
    }
   ],
   "source": [
    "n=int(input())\n",
    "result=[]\n",
    "for _ in range(n):\n",
    "    i=input()\n",
    "    result.append(format(int(i,16),'o'))#若 x 为纯数字，则不能有 base 参数，否则报错；其作用为对入参 x 取整\n",
    "for _ in result:\n",
    "    print(_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　从键盘输入一个不超过8位的正的十六进制数字符串，将它转换为正的十进制数后输出。\n",
    "　　注：十六进制数中的10~15分别用大写的英文字母A、B、C、D、E、F表示。\n",
    "样例输入\n",
    "FFFF\n",
    "样例输出\n",
    "65535\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n=input()\n",
    "print(format(int(n,16),'d'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定一个单词，请使用凯撒密码将这个单词加密。\n",
    "\n",
    "　　凯撒密码是一种替换加密的技术，单词中的所有字母都在字母表上向后偏移3位后被替换成密文。即a变为d，b变为e，…，w变为z，x变为a，y变为b，z变为c。\n",
    "\n",
    "　　例如，lanqiao会变成odqtldr。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lanqiao\n",
      "odqtldr"
     ]
    }
   ],
   "source": [
    "caesar_cipher_dict={'a':'d','b':'e','c':'f','d':'g','e':'h','f':'i','g':'j','h':'k','i':'l','j':'m','k':'n','l':'o','m':'p','n':'q','o':'r','p':'s','q':'t','r':'u','s':'v','t':'w','u':'x','v':'y','w':'z','x':'a','y':'b','z':'c'} \n",
    "chars=input()\n",
    "result=[]\n",
    "\n",
    "for i in range(len(chars)):\n",
    "    result.append(caesar_cipher_dict[chars[i]])\n",
    "for _ in result:\n",
    "    print(_,end='')\n",
    "#print(''.join(map(str,result))) #不换行输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　小明要用二进制来表示 1 到 10000 的所有整数，要求不同的整数用不同的二进制数表示，请问，为了表示 1 到 10000 的所有整数，至少需要多少个二进制位？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10011100010000\n"
     ]
    }
   ],
   "source": [
    "print(format(int('10000',10),'b'))#14"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　请问在 1 到 2020 中，有多少个数既是 4 的整数倍，又是 6 的整数倍。\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "168\n"
     ]
    }
   ],
   "source": [
    "count=0\n",
    "for i in range(1,2021):\n",
    "    if i%4==0 and i%6==0:\n",
    "        count+=1\n",
    "print(count)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　请问有多少个序列满足下面的条件：\n",
    "　　1. 序列的长度为 5。\n",
    "　　2. 序列中的每个数都是 1 到 10 之间的整数。\n",
    "　　3. 序列中后面的数大于等于前面的数。\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2002\n"
     ]
    }
   ],
   "source": [
    "def judge(arr):\n",
    "    length=len(arr)\n",
    "    for i in range(length-1):\n",
    "        if arr[i]<=arr[i+1]:\n",
    "            continue\n",
    "        else:\n",
    "            return False\n",
    "    return True\n",
    "count=0\n",
    "for i in range(1,11):\n",
    "    for j in range(1,11):\n",
    "        for k in range(1,11):\n",
    "            for m in range(1,11):\n",
    "                for n in range(1,11):\n",
    "                    arr=[i,j,k,m,n]\n",
    "                    if judge(arr):\n",
    "                        count+=1\n",
    "print(count)    \n",
    "                  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　两个字母之间的距离定义为它们在字母表中位置的距离。例如 A 和 C 的距离为 2，L 和 Q 的距离为 5。\n",
    "　　对于一个字符串，我们称字符串中两两字符之间的距离之和为字符串的内部距离。\n",
    "　　例如：ZOO 的内部距离为 22，其中 Z 和 O 的距离为 11。\n",
    "　　请问，LANQIAO 的内部距离是多少？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L   A\n",
      "L   N\n",
      "L   Q\n",
      "L   I\n",
      "L   A\n",
      "L   O\n",
      "A   N\n",
      "A   Q\n",
      "A   I\n",
      "A   A\n",
      "A   O\n",
      "N   Q\n",
      "N   I\n",
      "N   A\n",
      "N   O\n",
      "Q   I\n",
      "Q   A\n",
      "Q   O\n",
      "I   A\n",
      "I   O\n",
      "A   O\n",
      "162\n"
     ]
    }
   ],
   "source": [
    "a=\"LANQIAO\"\n",
    "sum=0\n",
    "for i in range(len(a)-1):\n",
    "    for j in range(i,len(a)-1):\n",
    "                print(a[i],\" \",a[j+1])\n",
    "                sum+=abs(ord(a[i])-ord(a[j+1]))\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　现在时间是 a 点 b 分，请问 t 分钟后，是几点几分？\n",
    "输入格式\n",
    "　　输入的第一行包含一个整数 a。\n",
    "　　第二行包含一个整数 b。\n",
    "　　第三行包含一个整数 t。\n",
    "输出格式\n",
    "　　输出第一行包含一个整数，表示结果是几点。\n",
    "　　第二行包含一个整数，表示结果是几分。\n",
    "样例输入\n",
    "3\n",
    "20\n",
    "165\n",
    "样例输出\n",
    "6\n",
    "5\n",
    "样例输入\n",
    "3\n",
    "20\n",
    "175\n",
    "样例输出\n",
    "6\n",
    "15\n",
    "数据规模和约定\n",
    "　　对于所有评测用例，0 <= a <= 23, 0 <= b <= 59, 0 <= t, t 分钟后还是在当天。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "20\n",
      "175\n",
      "6\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "input_hours=int(input())\n",
    "input_minutes=int(input())\n",
    "t=int(input())\n",
    "now_all_minutes=input_hours*60+input_minutes\n",
    "after_minutes=now_all_minutes+t\n",
    "print(after_minutes//60)\n",
    "print(after_minutes%60)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　小蓝有一张黑白图像，由 n * m 个像素组成，其中从上到下共 n 行，每行从左到右 m 列。每个像素由一个 0 到 255 之间的灰度值表示。\n",
    "　　现在，小蓝准备对图像进行模糊操作，操作的方法为：\n",
    "　　对于每个像素，将以它为中心 3 * 3 区域内的所有像素（可能是 9 个像素或少于 9 个像素）求和后除以这个范围内的像素个数（取下整），得到的值就是模糊后的结果。\n",
    "　　请注意每个像素都要用原图中的灰度值计算求和。\n",
    "输入格式\n",
    "　　输入的第一行包含两个整数 n, m。\n",
    "　　第 2 行到第 n + 1 行每行包含 m 个整数，表示每个像素的灰度值，相邻整数之间用一个空格分隔。\n",
    "输出格式\n",
    "　　输出 n 行，每行 m 个整数，相邻整数之间用空格分隔，表示模糊后的图像。\n",
    "样例输入\n",
    "3 4\n",
    "0 0 0 255\n",
    "0 0 255 0\n",
    "0 30 255 255\n",
    "样例输出\n",
    "0 42 85 127\n",
    "5 60 116 170\n",
    "7 90 132 191\n",
    "数据规模和约定\n",
    "　　对于所有评测用例，1 <= n, m <= 100。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import copy\n",
    "n,m=map(int,(input().split()))\n",
    "arr=[]   \n",
    "for _ in range(n):\n",
    "    arr.append(list(map(int,input().split())))\n",
    "\n",
    "def conv(arr,i,j):\n",
    "    if i==0 and j==0:\n",
    "        return (arr[i][j]+arr[i][j+1]+arr[i+1][j]+arr[i+1][j+1])//4\n",
    "    if i==0 and j==m-1:\n",
    "        return (arr[i][j]+arr[i][j-1]+arr[i+1][j]+arr[i+1][j-1])//4\n",
    "    if i==n-1 and j==m-1:\n",
    "        return (arr[i][j]+arr[i][j-1]+arr[i-1][j]+arr[i-1][j-1])//4\n",
    "    if i==n-1 and j==0:\n",
    "        return (arr[i][j]+arr[i][j+1]+arr[i-1][j]+arr[i-1][j+1])//4\n",
    "    if i==0 and j!=0 and j!=m-1:\n",
    "        return (arr[i][j]+arr[i][j-1]+arr[i][j+1]+arr[i+1][j]+arr[i+1][j-1]+arr[i+1][j+1])//6\n",
    "    if i==n-1 and j!=0 and j!=m-1:\n",
    "        return (arr[i][j]+arr[i][j-1]+arr[i][j+1]+arr[i-1][j]+arr[i-1][j-1]+arr[i-1][j+1])//6\n",
    "    if j==0 and i!=0 and i!=n-1:\n",
    "        return (arr[i][j]+arr[i+1][j]+arr[i-1][j]+arr[i][j+1]+arr[i-1][j+1]+arr[i+1][j+1])//6\n",
    "    if j==m-1 and i!=0 and i!=n-1:\n",
    "        return (arr[i][j]+arr[i+1][j]+arr[i-1][j]+arr[i][j-1]+arr[i+1][j-1]+arr[i-1][j-1])//6\n",
    "    else:\n",
    "        return(arr[i][j]+arr[i][j+1]+arr[i][j-1]+\n",
    "                arr[i+1][j]+arr[i+1][j+1]+arr[i+1][j-1]+\n",
    "              arr[i-1][j]+arr[i-1][j+1]+arr[i-1][j-1])//9\n",
    "\n",
    "result=copy.deepcopy(arr)\n",
    "    \n",
    "for i in range(n):\n",
    "    for j in range(m):\n",
    "        result[i][j]=conv(arr,i,j)\n",
    "\n",
    "    \n",
    "for i in range(n):\n",
    "    for j in range(m):\n",
    "        print(result[i][j],end=' ')\n",
    "    print('\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6973\n"
     ]
    }
   ],
   "source": [
    "chars=\"\"\n",
    "for i in range(1,2021):\n",
    "    chars=chars+str(i)\n",
    "print(len(chars))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "5\n",
      "12.5\n"
     ]
    }
   ],
   "source": [
    "I=int(input())\n",
    "J=int(input())\n",
    "print(\"{:.1f}\".format(I*J/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LANQIAO\n",
      "3\n",
      "f ANQIAO\n",
      "f LNQIAO\n",
      "f LAQIAO\n",
      "f LANIAO\n",
      "f LANQAO\n",
      "f LANQIO\n",
      "f LANQIA\n",
      "f NQIAO\n",
      "f AQIAO\n",
      "f ANIAO\n",
      "f ANQAO\n",
      "f ANQIO\n",
      "f ANQIA\n",
      "f NIAO\n",
      "f AIAO\n",
      "f ANAO\n",
      "f ANIO\n",
      "f ANIA\n",
      "AIAO\n"
     ]
    }
   ],
   "source": [
    "a = input()\n",
    "b = int(input())\n",
    "while b:\n",
    "    d = 0\n",
    "    c = []\n",
    "    b = b-1\n",
    "    for i in range(len(a)):\n",
    "        f = a[:d] + a[d+1:]\n",
    "        print(\"f\",f)\n",
    "        c.append(f)\n",
    "        d = d + 1\n",
    "    a = min(c)\n",
    "print(a)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间)，它们之间的关系是以下4中情况之一：\n",
    "　　1：两个字符串长度不等。比如 Beijing 和 Hebei\n",
    "　　2：两个字符串不仅长度相等，而且相应位置上的字符完全一致(区分大小写)，比如 Beijing 和 Beijing\n",
    "　　3：两个字符串长度相等，相应位置上的字符仅在不区分大小写的前提下才能达到完全一致（也就是说，它并不满足情况2）。比如 beijing 和 BEIjing\n",
    "　　4：两个字符串长度相等，但是即使是不区分大小写也不能使这两个字符串一致。比如 Beijing 和 Nanjing\n",
    "　　编程判断输入的两个字符串之间的关系属于这四类中的哪一类，给出所属的类的编号。\n",
    "输入格式\n",
    "　　包括两行，每行都是一个字符串\n",
    "输出格式\n",
    "　　仅有一个数字，表明这两个字符串的关系编号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Beijing\n",
      "Nanjing\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "def slove(str1, str2):\n",
    "    if len(str1) != len(str2):\n",
    "        return 1\n",
    "    else:\n",
    "        if str1 == str2:\n",
    "            return 2\n",
    "        elif str1.lower() != str2.lower():\n",
    "            return 4\n",
    "        return 3\n",
    "if __name__ == '__main__':\n",
    "    str1 = input()\n",
    "    str2 = input()\n",
    "    print(slove(str1, str2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：400.0MB\n",
    "问题描述\n",
    "　　有一个数x，求从1加到x的值\n",
    "输入格式\n",
    "　　输入一行，一个数x。\n",
    "输出格式\n",
    "　　输出1行，从一加到x的值\n",
    "样例输入\n",
    "10\n",
    "样例输出\n",
    "55\n",
    "数据规模和约定\n",
    "　　1＜x＜10000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "x=int(input())\n",
    "print(\"{:.0f}\".format(x+x*(x-1)/2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：256.0MB\n",
    "问题描述\n",
    "　　两个强盗刚刚抢到一条十分珍贵的珍珠项链，正在考虑如何分赃。由于他们不想破坏项链的美观，所以只想把项链分成两条连续的珍珠链。然而亲兄弟明算账，他们不希望因为分赃不均导致不必要的麻烦，所以他们希望两条珍珠链的重量尽量接近。于是他们找到了你，希望让你帮忙分赃。\n",
    "　　我们认为珍珠项链是由n颗不同的珍珠组成的，我们可以通过称重，分别称出每颗珍珠的重量（我们忽略连接珍珠的“链”的重量）。你要求的是每个人至少能得到多重的珍珠（即分赃少的那个人能得到多重的珍珠）。\n",
    "输入格式\n",
    "　　第一行一个整数n，表示这个珍珠项链有多少颗珍珠。第二行n个整数，顺时针给出每颗珍珠的重量wi。（你要注意的是，第一课珍珠和最后一颗珍珠是相连的）\n",
    "输出格式\n",
    "　　一个整数，表示分赃少的那个人能得到多重的珍珠。\n",
    "样例输入\n",
    "7\n",
    "1 2 3 4 3 2 1\n",
    "样例输出\n",
    "7\n",
    "数据规模和约定\n",
    "　　对于30%的数据，n<=200；\n",
    "　　对于60%的数据，n<=2000；\n",
    "　　对于100%的数据，n<=50000，0<wi<=1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "1 2 3 4 3 2 1\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "n=int(input())\n",
    "wi_lis=list(map(int,input().split()))\n",
    "half_all=sum(wi_lis)/2\n",
    "i=0\n",
    "weight=0\n",
    "j=0\n",
    "result_weight=[]\n",
    "while(1):\n",
    "    weight+=wi_lis[i%n]\n",
    "    weight_add_one=weight+wi_lis[(i+1)%n]\n",
    "    i+=1\n",
    "    if weight<half_all and weight_add_one>half_all:\n",
    "        result_weight.append(weight)\n",
    "        weight=0\n",
    "        j+=1\n",
    "        i=j\n",
    "    if j==n:\n",
    "        break\n",
    "print(max(result_weight))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
